/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package vehicle.bol;

/**
 *
 * @author khoang
 */
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import vehicle.dal.DAL;
import vehicle.entity.Brands;
import vehicle.entity.TypeVehicle;

public class BrandBol {

    public List<Brands> ReportBrand() {
        DAL dal = new DAL();
        List<Brands> listBr = new ArrayList<Brands>();
        try {
            ResultSet rs = dal.executeQuery("reportBrands", new ArrayList());
            while (rs.next()) {
                Brands brand = new Brands();
                brand.setBrandID(rs.getInt("BrandID"));
                brand.setBrandName(rs.getString("BrandName"));
                brand.setLogo(rs.getString("Logo"));
                brand.setADDRESS(rs.getString("ADDRESS"));
                brand.setTotalCount(rs.getInt("TotalCount"));
                listBr.add(brand);
            }
        } catch (Exception e) {
        } finally {
            dal.closeConnection();
        }
        return listBr;
    }

    public List<Brands> getAllBrand() {
        DAL dal = new DAL();
        List<Brands> listBr = new ArrayList<Brands>();
        try {
            ResultSet rs = dal.executeQuery("usp_Get_All_Brand", new ArrayList());
            while (rs.next()) {
                Brands brand = new Brands();
                brand.setBrandID(rs.getInt("BrandID"));
                brand.setBrandName(rs.getString("BrandName"));
                brand.setListtype(getTypeVehicle(brand.getBrandID()));
                listBr.add(brand);
            }
        } catch (Exception e) {
        } finally {
            dal.closeConnection();
        }
        return listBr;
    }

     public List<Brands> layPhanTramBanDuoc() {
        DAL dal = new DAL();
        List<Brands> listBr = new ArrayList<Brands>();
        ArrayList li = new ArrayList();
        Calendar cal = Calendar.getInstance();
        int year = cal.get(Calendar.YEAR);
        li.add(year);
        try {
            ResultSet rs = dal.executeQuery("usp_Get_Percen_Brand", li);
            while (rs.next()) {
                Brands brand = new Brands();
                brand.setPercen(rs.getFloat("Percen"));
                brand.setBrandName(rs.getString("BrandName"));
                listBr.add(brand);
            }
        } catch (Exception e) {
        } finally {
            dal.closeConnection();
        }
        return listBr;
    }

    public List<Brands> laySoLuongTheoThang() {
        DAL dal = new DAL();
        List<Brands> listBr = new ArrayList<Brands>();
        ArrayList li = new ArrayList();
        Calendar cal = Calendar.getInstance();
        int year = cal.get(Calendar.YEAR);
        li.add(year);
        try {
            ResultSet rs = dal.executeQuery("usp_thongke", li);
            while (rs.next()) {
                Brands brand = new Brands();
                brand.setBrandName(rs.getString("BrandName"));

                brand.setBrandID(rs.getInt("Thangdau"));

                brand.setTotalCount(rs.getInt("thangcuoi"));

                listBr.add(brand);
            }
        } catch (Exception e) {
        } finally {
            dal.closeConnection();
        }
        return listBr;
    }

    public List<TypeVehicle> getTypeVehicle(int BrandId) {
        DAL dal = new DAL();
        List<TypeVehicle> listType = new ArrayList<TypeVehicle>();
        ArrayList li = new ArrayList();
        li.add(BrandId);
        try {
            ResultSet rs = dal.executeQuery("usp_Get_Type_BY_BrandID", li);
            while (rs.next()) {
                TypeVehicle type = new TypeVehicle();
                type.setTypeID(rs.getInt("TypeID"));
                type.setTypeName(rs.getString("TypeName"));
                listType.add(type);
            }
        } catch (Exception e) {
        } finally {
            dal.closeConnection();
        }
        return listType;
    }
    public List<String> typeVehicleByBrandName(String BrandName) {
        DAL dal = new DAL();
        List<String> listType = new ArrayList<String>();
        ArrayList li = new ArrayList();
        li.add(BrandName);
        try {
            ResultSet rs = dal.executeQuery("typeVehicleByBrandName", li);
            while (rs.next()) {
                listType.add(rs.getString("TypeName"));
            }
        } catch (Exception e) {
        } finally {
            dal.closeConnection();
        }
        return listType;
    }
}

